#!/bin/sh -e

TOP_DIR=$(pwd)

. CI/travis/lib.sh

handle_default() {
	mkdir -p build
	cd build

	#create deb for bindings
	cmake -DENABLE_PYTHON=ON -DENABLE_TOOLS=ON -DENABLE_CSHARP=OFF -DENABLE_LOG=ON -DBUILD_EXAMPLES=ON .. && make
	sudo python3 setup.py --command-packages=stdeb.command sdist_dsc
	cd "$(find . -type d -name "debian" | head -n 1)"
	sudo env DEB_BUILD_OPTIONS=nocheck debuild -us -uc
	cp ../../*.deb ${TOP_DIR}/build/
	cd ${TOP_DIR}/build/
	#remove the tar.gz for bindings
	sudo rm *.tar.gz

	#create simple .deb without Python bindings
	cmake -DENABLE_PACKAGING=ON -DDEB_DETECT_DEPENDENCIES=ON -DENABLE_PYTHON=OFF -DENABLE_CSHARP=ON -DENABLE_TOOLS=ON -DENABLE_LOG=ON -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_EXAMPLES=ON ..
	make && make package
	ls
}

handle_centos() {
	mkdir -p build
	cd build
	cmake -DENABLE_PACKAGING=ON -DENABLE_PYTHON=OFF -DENABLE_CSHARP=ON -DENABLE_TOOLS=ON -DENABLE_LOG=ON -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_EXAMPLES=ON ..
	make && make package
	cd ..
}

handle_generic_docker() {
	run_docker_script inside_docker.sh
}

handle_doxygen() {
	mkdir -p build
	cd build
	cmake -DENABLE_PYTHON=ON -DENABLE_CSHARP=OFF -DENABLE_DOC=ON ..
	make && sudo make install
	make doc
	cd ..
	./CI/travis/doxygen.sh
}

handle_ubuntu() {
	handle_default
}

handle_debian() {
	handle_default
}

handle_generic_docker() {
	run_docker_script inside_docker.sh
}

setup_build_type_env_vars

handle_${BUILD_TYPE}
